package com.farm.filter;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.farm.mapper.SusceptibleMapper;
import com.farm.pojo.Susceptible;
import com.farm.sensitiveWords.SensitiveWordFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class SusceptibleFilter {
    @Autowired
    private SusceptibleMapper susceptibleMapper;

    public  String WordFilter(String word){
        ArrayList<String> stringList = new ArrayList<>();
        LambdaQueryWrapper<Susceptible> lqw = new LambdaQueryWrapper<>();
        lqw.select(Susceptible::getContent);
        List<Susceptible> susceptibleList = susceptibleMapper.selectList(lqw);
        if ( susceptibleList != null && susceptibleList.size() > 0 ){
            for (Susceptible susceptible : susceptibleList){
                stringList.add(susceptible.getContent());
            }
        }
        SensitiveWordFilter.loadWord( stringList);
        String result = SensitiveWordFilter.Filter(word);
        return result;
    }
}
